package oop;

/**
 * 测试组合
 * 核心：将父类对象作为子类的属性
 * 组合可以有多个属性，继承只能有一个父类
 */
/*is-a 关系用继续，has-a关系用组合  Student is a person,这个逻辑没有问题
  但是：Student has a person 就有问题，显然继承关系更适合*/
public class TestComponent {

    public static void main(String[] args) {

    }
}
class Person2 {
    int height;
    String name;
    public void rest2(){
        System.out.println("休息");
    }
}
class Student2 {
    //组合  将父类对象作为子类的属性   可以有多个属性
    Person2 p2 = new Person2();
    Boy2 boy2 = new Boy2("jack",172,"踢球");//因为是构造器，要输入值
    Girl girl = new Girl();
    String major; //专业

    public void Study(){
        System.out.println("学习");
        p2.rest2();
        System.out.println(this.boy2.interest);//调用Boy2类的属性
        System.out.println(this.p2.name);//调用Person2,要在this后加p2,指名哪个类
        girl.like();
        System.out.println(this.girl.height);
    }
    //构造器
    public Student2(String name,int height,String major) {
        this.p2.name = name;
        this.p2.height = height;
        this.major = major;//本身Student的属性
    }
}
class Boy2 /*extends Person*/ {
    String interest;//兴趣
    public Boy2(String name2,int height2,String interest){
        String name1 = name2;
        int height1 = height2;
        this.interest = interest;
    }
}
class Girl {
    String name;
    int height;
    int weight;
    public void like() {
        System.out.println("唱k");
    }
}